#include <stdio.h>
#include <stdlib.h>

#define true 1
#define false 0

typedef int bool;

char** matrix = NULL;
int nrow = 0, ncol = 0;
int nmouserow = 0, nmousecol = 0;



bool testinputend()
{
    if(nrow == 0 && ncol == 0
            && nmouserow == 0 && nmousecol == 0)
        return true;
    return false;
}

char getmatrixchar(int x, int y)
{
    if(x < 0 || x >= nrow || y < 0 || y >= ncol )
        return '.';
    return matrix[x][y];
}

int getperimeter(int x, int y, int nextxy[8][2])
{
    int i = 0, j = 0, k = 0;
    int ncount = 0;

    for(i = x-1; i <= x+1; i++)
    {
        for(j = y-1; j <= y+1; j++)
        {
            if(i != x || j != y)
            {
                nextxy[k][0] = i;
                nextxy[k][1] = j;
                k++;
            }
        }
    }

    if(getmatrixchar(x-1,y) == '.')
        ncount++;
    if(getmatrixchar(x+1,y) == '.')
        ncount++;
    if(getmatrixchar(x,y-1) == '.')
        ncount++;
    if(getmatrixchar(x,y+1) == '.')
        ncount++;
    return ncount;


}

void caluperimeter(int x, int y, int* sum)
{
    int perimeter = 0;
    int i = 0;
    int nextx = 0, nexty = 0;
    int nextxy[8][2] =
    {{0, 0}, {0, 0}, {0, 0}, {0, 0},{0, 0}, {0, 0}, {0, 0}, {0, 0}};

    perimeter = getperimeter(x, y, nextxy);

    for(i = 0; i < 8; i++)
    {
        //printf("nextx: %d nexty: %d\r\n", nextxy[i][0], nextxy[i][1]);
    }

    *sum = *sum + 2*perimeter - 4;

//    if(perimeter == 4)
//    {
//        printf("perimeter: %d\r\n", sum);
//        return;
//    }

    matrix[x][y] = '.';

    //printmatrix();


    for(i = 0; i < 8; i++)
    {
        nextx = nextxy[i][0];
        nexty = nextxy[i][1];
        if(nextx >= 0 && nextx < nrow &&
           nexty >= 0 && nexty < ncol && matrix[nextx][nexty] != '.')
        {
            //printf("x:%d y:%d nextx: %d nexty:%d sum:%d\r\n", x, y, nextx, nexty, *sum);
            caluperimeter(nextx, nexty, sum);
        }
    }

}

void getinput()
{
    int i = 0, j = 0;
    char str[25];
    for(i = 0; i < nrow; i++)
    {
        scanf("%s", str);
        for(j = 0; j < ncol; j++)
        {
            matrix[i][j] = str[j];
        }
    }
}



void printmatrix()
{
    int i = 0, j = 0;

    printf("row: %d, col:%d,  nmousex: %d, nmousey: %d\r\n", nrow, ncol, nmouserow, nmousecol);
    for(i = 0; i < nrow; i++)
    {
        for(j = 0; j < ncol; j++)
        {
            printf("%c \t", matrix[i][j]);
        }
        printf("\r\n");
    }
}

void process()
{
    int perimeter = 0;
    caluperimeter(nmouserow-1, nmousecol-1, &perimeter);
    printf("%d\r\n", perimeter);
}

void freematrix()
{
    int i = 0;

    for(i = 0; i < nrow; i++)
    {
        free(matrix[i]);
    }
    free(matrix);
    matrix = NULL;
}

int main()
{
    int i = 0;
    //freopen("bin\\debug\\in.txt", "r", stdin);
    //freopen("bin\\debug\\out.txt", "w", stdout);

    scanf("%d %d %d %d", &nrow, &ncol, &nmouserow, &nmousecol);
    while(testinputend() == false)
    {
        matrix = (char**)malloc(nrow * sizeof(char*));
        for(i = 0; i < nrow; i++)
        {
            matrix[i] = (char*)malloc(ncol * sizeof(char));
        }
        getinput();
        //printmatrix();
        process();
        freematrix();

        scanf("%d %d %d %d", &nrow, &ncol, &nmouserow, &nmousecol);
    }


    return 0;
}
